<?php

/**
 * @version: 1.5
 * @Project: MightMedia TVS
 * @Puslapis: www.coders.lt
 * @$LastChangedBy$
 * @copyright CodeRS ©2009
 * @license GNU General Public License v2
 * @$LastChangedRevision$
 * @$LastChangedDate$
 * @$HeadURL$
 **/

//Nustatom *pilna* URL iki esamo puslapio (protocol, server, path, query parametrai, ir t.t.)
function full_url() {
	$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
	$protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]),0,strpos(strtolower($_SERVER["SERVER_PROTOCOL"]),"/")) . $s;
	$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":" . $_SERVER["SERVER_PORT"]);
	return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port;
}

// Sukišam i _GET kintamuosius iš FRIENDLY URLS
pick_off(true);

//mod_rewrite URL
//.htacess
function pick_off($grabFirst = false,$sep = "/") {
	$arr = explode($sep,trim($_SERVER['REQUEST_URI'],$sep));
	if ($grabFirst) $_GET['id'] = array_shift($arr);
	while (count($arr) > 0) $_GET[array_shift($arr)] = array_shift($arr);
	return (count($_GET) > 0) ? $_GET : false;
}

//Automatiškai užkrauname pluginus
function __autoload($class_name) {
	$class_name = strtolower($class_name);
	if ($class_name == 'smarty') {
		require __CFG_ROOT . 'priedai/smarty/Smarty.class.php';
	}
	else {
		require __CFG_ROOT . 'priedai/plugin.' . strtolower($class_name) . '.php';
	}
}

//Sukuria friendly URL is stingo
function friendly_url($str) {
	$str = preg_replace("/[^a-zA-Z0-9 ]/","",$str);
	$str = strtolower(str_replace(" ","-",trim($str)));
	return $str;
}

?>
